function model = ReadModelFile(fname)
% clear;clc;close all; fname = 'bckup-01-26-2014/modelfile_features-alerts-used-01-11-2014_meetings-train-1.txt';

fprintf('Reading LR modelfile ... ');
fid = fopen(fname,'r');
tline = fgets(fid);
count = 1;

modelMap = containers.Map('KeyType','int32','ValueType','double');
while ischar(tline)
    if(~isempty(strfind(tline,'betaClassSparse')))
        line = strrep(tline(strfind(tline,'@constant'):end),'@constant','0');
        if(isempty(line))
            line = strrep(tline,'betaClassSparse 0','');
            if(isempty(line) || strcmp(line(1:15),'betaClassSparse'))
                line = strrep(tline,'betaClassSparse -1','');
                if(isempty(line) || strcmp(line(1:15),'betaClassSparse'))
                    line = strrep(tline,'betaClassSparse 1','');
                end
            end
        end
        components = strsplit(line,' ');
        bNegClass = false;
        if(~isempty(strfind(tline,'betaClassSparse 0')) || ~isempty(strfind(tline,'betaClassSparse -1')))
            bNegClass = true;
        end
        for i = 1:length(components),
            fprintf('Processing %d of %d variables\n',i,length(components));
            parts = strsplit(components{i},':');
            key = str2num(parts{1});
            value = str2num(parts{2});
            if(bNegClass)
                value = -value;
            end
            if(modelMap.isKey(key))
                modelMap(key) = modelMap(key) + value;
            else
                modelMap(key) = value;
            end
        end
    end
    tline = fgets(fid);
    count = count + 1;
end
fclose(fid);
fprintf('Done.');

keys = modelMap.keys;
keys = [keys{:}];
model = zeros(length(keys),2);
for i=1:length(keys),
    model(i,1) = keys(i);
    model(i,2) = modelMap(keys(i));
end

[~,inds] = sortrows(abs(model),2);
model = flipud(model(inds,:));

model = sortrows(model);
return